using System;
using System.Collections.Generic;
using System.Text;
//
namespace smalltest
{
    using System;
    using System.Collections.Generic;


    public class A1 {
        public string a;
        public A1(string z) { a = z; }
    }


    //The interface for calculations.
    //This will normally contain much more methods,
    // but for the benchmark we have just Add
    public interface ICalculator<T>
    {
        T Add(T a, T b);
    }
    //You would have to do something similar to this
    //for each type you want to use in your list.
    public struct DoubleCalculator : ICalculator<double>
    {
        public double Add(double a, double b) { return a + b; }
    }
    public class Test
    {
        //create a large List<double> for benchmarking
        static List<double> list;
        static Test()
        {
            list = new List<double>(1000000);
            for (int i = 0; i < 1000000; i++)
                list.Add(i);
        }
        //the non-generic sum method
        public static double Sum(List<double> list)
        {
            double sum = 0;
            for (int i = 0; i < list.Count; i++)
                sum += list[i];
            return sum;
        }
        //the generic sum method. Note the second type parameter.
        public static T Sum<T, C>(List<T> list)
            where T : new()
            where C : ICalculator<T>, new()
        {
            C calculator = new C();
            T sum = new T();
            for (int i = 0; i < list.Count; i++)
                sum = calculator.Add(sum, list[i]);
            return sum;
        }
        public static A1 test(A1 a) {
            return a;
        }

        public static void Main()
        {
#if(DEBUG)
            Console.WriteLine("Warning: Benchmarking in debug mode will not produce meaningful results!");
#endif



           /* Console.WriteLine("Warmup");
            DateTime time0;
            time0 = DateTime.Now;
           
            Console.WriteLine("warump {0}.", (DateTime.Now - time0));   
            time0 = DateTime.Now;
            for (int i = 0; i < 100; i++)
                Sum(list);
            Console.WriteLine("Non-generic sum took {0}.", (DateTime.Now - time0));
            time0 = DateTime.Now;
            for (int i = 0; i < 100; i++)
                Sum<double, DoubleCalculator>(list);
            Console.WriteLine("Generic sum took {0}.", (DateTime.Now - time0));
            
            int p = 1<<8;
            int[] A = new int[1<<16];
            int l = 1<<16;
            for (int i = 2; i < p; i++) {
                for (int ii = i*2; ii < (1 << 16); ii += i) {
                    if (A[ii] == 0) l--;
                    A[ii]++;
                }
            }
            int ll=0;
            Int64 akt=1;
            for (int i = 1; i < (1 << 16); i++)
            {
                if (A[i] == 0) akt *= i;
                if (akt > ((Int64)1 << 32)) { akt = 1; ll++; }
            }
            Console.WriteLine("" + ll);*/
            Console.ReadLine();
        }
    }
}
